<?php

namespace models\DAO;

use models\Exception\DAO\ModelDriverException;
use models\Exception\DAO\ModelException;
use models\Exception\DAO\ModelReflectionException;
use models\Exception\DAO\ModelSqlException;


/**
 * @SWG\Swagger(
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabashippingSingleData",
 *          required={"errno", "errmsg", "data"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", type="object", ref="#/definitions/alibabashippingSingleObj")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabashippingSingleObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/alibabashippingSingle")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabashippingListData",
 *          required={"errno", "errmsg", "result"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", ref="#/definitions/alibabashippingListObj"),
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabashippingListObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/alibabashippingData"),
 *          @SWG\Property(property="meta", ref="#/definitions/meta")
 *     ),
 *     @SWG\Definition(
 *          type="array",
 *          definition="alibabashippingData",
 *          @SWG\Items(
 *              title="data", ref="#/definitions/alibabashippingSingle"
 *          )
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabashippingSingle",
 *          @SWG\Property(property="id", type="integer", format="int32",  description="主键"),
 *          @SWG\Property(property="product_id", type="string", format="string",  description="1688商品编号"),
 *          @SWG\Property(property="charge_type", type="integer", format="int32",  description="计件类型(0为重量,1为件数,2为体积,默认0)"),
 *          @SWG\Property(property="freight_template_id", type="integer", format="int32",  description="运费模板ID(0为运费说明,1为卖家承担运费,其他值表示使用运费模版)"),
 *          @SWG\Property(property="unit_weight", type="string", format="string",  description="重量/毛重"),
 *          @SWG\Property(property="send_goods_address_id", type="integer", format="int32",  description="发货地址ID"),
 *          @SWG\Property(property="send_goods_address_text", type="string", format="string",  description="发货地描述"),
 *          @SWG\Property(property="to_area_code_text", type="string", format="string",  description="目的地地址编码文本"),
 *          @SWG\Property(property="suttle_weight", type="string", format="string",  description="净重"),
 *          @SWG\Property(property="height", type="string", format="string",  description="高度"),
 *          @SWG\Property(property="width", type="string", format="string",  description="宽度"),
 *          @SWG\Property(property="length", type="string", format="string",  description="长度"),
 *          @SWG\Property(property="channel_price_free_postage", type="integer", format="int32",  description="厂货通渠道专享价是否包邮，要结合非包邮地址，如果收货地址在非包邮地区则商品为不包邮"),
 *          @SWG\Property(property="channel_price_exclude_areaCodes", type="string", format="string",  description="厂货通渠道专享价非包邮地区（地址信息列表，省份信息"),
 *          @SWG\Property(property="first_unit", type="integer", format="int32",  description="首重"),
 *          @SWG\Property(property="first_unit_fee", type="integer", format="int32",  description="首重或首件的价格(单位:元)"),
 *          @SWG\Property(property="next_unit", type="integer", format="int32",  description="续重"),
 *          @SWG\Property(property="next_unit_fee", type="integer", format="int32",  description="续重件价格(单位:元)"),
 *     )
 * )
 */
class AlibabashippingModel extends BaseModel{
    /**
     * 主键
     */
    public $id = null;

    /**
     * 1688商品编号
     */
    public $product_id = null;

    /**
     * 计件类型(0为重量,1为件数,2为体积,默认0)
     */
    public $charge_type = null;

    /**
     * 运费模板ID(0为运费说明,1为卖家承担运费,其他值表示使用运费模版)
     */
    public $freight_template_id = null;

    /**
     * 重量/毛重
     */
    public $unit_weight = null;

    /**
     * 发货地址ID
     */
    public $send_goods_address_id = null;

    /**
     * 发货地描述
     */
    public $send_goods_address_text = null;

    /**
     * 目的地地址编码文本
     */
    public $to_area_code_text = null;

    /**
     * 净重
     */
    public $suttle_weight = null;

    /**
     * 高度
     */
    public $height = null;

    /**
     * 宽度
     */
    public $width = null;

    /**
     * 长度
     */
    public $length = null;

    /**
     * 厂货通渠道专享价是否包邮，要结合非包邮地址，如果收货地址在非包邮地区则商品为不包邮
     */
    public $channel_price_free_postage = null;

    /**
     * 厂货通渠道专享价非包邮地区（地址信息列表，省份信息
     */
    public $channel_price_exclude_areaCodes = "";

    /**
     * 首重
     */
    public $first_unit = null;

    /**
     * 首重或首件的价格(单位:元)
     */
    public $first_unit_fee = null;

    /**
     * 续重
     */
    public $next_unit = null;

    /**
     * 续重件价格(单位:元)
     */
    public $next_unit_fee = null;
    /**
     * DAO对象
     */
    public $obj = '';

    /**
     * DAO对象数组
     */
    public $data = [];

    /**
     * 翻页对象
     */
    public $meta = null;

    /**
     * 当前页
     */
    public $page = 1;

    /**
     * 每页显示条数
     */
    public $page_size = 10;

    /**
     * 主键数组
     */
    public $primary_key_arr = ["id"];

    /**
     * 自增字段数组
     */
    public $auto_increment_key_arr = ["id"];

    /**
     * 唯一字段
     */
    public $unique_key_arr = '';

    /**
     * 单例实例
     */
    static public $instance = null;

    /**
     * @return AlibabashippingModel|null
     * @throws ModelSqlException
     */
    static public function getInstance() {
        if(is_null(self::$instance)){
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * AlibabashippingModel constructor.
     * @throws ModelSqlException
     */
    public function __construct() {
        parent::__construct(str_replace("Model", "", substr(get_class($this), strrpos(get_class($this), "\\")+1)));
        $this->meta = new \stdClass();
    }

    /**
     * @throws ModelException
     */
    public function __clone() {
        throw new ModelException(
            str_replace('%s', get_class($this), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE_NO);
    }

    public function __destruct() {
        self::$instance = null;
    }

    /**
     * set属性
     *
     * __set.
     * @param string $name 参数名
     * @param string $value 参数值
     * @return $this
     */
    public function __set($name = "", $value = "") {
        $this->$name = $value;
        return $this;
    }

    /**
     * get属性
     *
     * __get.
     * @param string $name 参数名
     * @return mixed
     */
    public function __get($name = "") {
        return  $this->$name ;
    }

    /**
     * 创建alibabashippingModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function insert() {
        return $this->insertRecord();
    }

    /**
     * 编辑alibabashippingModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function update() {
        return $this->updateRecord();
    }

    /**
     * 删除alibabashippingModel，需先指定主键
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function delete() {
        return $this->deleteRecord();
    }

    /**
     * 根据主键查询alibabashippingModel，获取单条记录
     *
     * find.
     * @param int $primary_key 主键编号
     * @return $this
     * @throws ModelException
     * @throws ModelReflectionException
     */
    public function find($primary_key = 0) {
        $result = $this->findByPrimaryKey($primary_key);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询alibabashippingModel，获取多条记录
     *
     * findOneBy.
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findOneBy($condition = []) {
        $result = $this->findRecordBy($condition);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询alibabashippingModel，获取多条记录
     *
     * findBy.
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findBy($condition = []) {
        $count = $this->getCount($condition);
        $total = $count->fetchColumn();

        $this->data = [];
        $alib_obj = $this->findRecordBy($condition, $this->page, $this->page_size);

        $this->genMeta($total);
        $this->setModelProperty($alib_obj, true);

        return $this;
    }

    /**
     * 批量插入alibabashippingModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchInsert() {
        return $this->batchInsertRecord();
    }

    /**
     * 批量删除alibabashippingModel
     *
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchDelete() {
        $this->batchDeleteRecord();
    }

    /**
     * 生成批量生成update的sql
     *
     * @return bool|string
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function genBatchUpdateSql() {
        return $this->_genBatchUpdateSql();
    }

}
